<?php
use Doctrine\ORM\Mapping\Entity;
class Bemigo_Controller_Action_Base_Profile extends Bemigo_Controller_Action_Base{

	protected $_relationshipId;

	protected $_user;

	protected $_friend;

	public function init(){
		// Inherit parent init()
		parent::init();
		if($relation_id = $this->getRequest()->getParam('relation_id')){
			$this->setUserFriend($relation_id);
		}
	}

	/**
	 * @return Entity Users
	 * returns Doctrine Entity for logged in user
	 */
	protected function getUser(){
		return $this->_user;
	}

	protected function setUserFriend($relation_id){
		if(!empty($relation_id)){
			$em = $this->getEm();
			$relation=$em->find("Entities\\Friends",$relation_id);
			if(!empty($relation)){
				$this->_user = $relation->getUser();
				$this->_friend = $relation->getFriend();
			}else{
				throw new Exception("The profile being accessed is not available. Please logout and log back in or try selecting a different friend.");
			}
		}
	}

	/**
	 * @return Entity Users
	 * returns Doctrine Entity for logged in user's friend
	 */
	protected function getFriend(){
		return $this->_friend;
	}


	public function checkRelationship(){
		if($this->_facebook->getUser() != $this->_user->getFacebookId()){
			throw new Exception("Active user session not verified. Please logout and log back in.", 0);
		}
	}

}